<?php

namespace App\Console\Commands\OpenShop;

use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Enums\OpenShop\MissionTemplateEnum;
use App\Models\OpenShop\InvestmentPromotion\OpenShopAddressModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Service\OpenShop\Feishu\MissionTemplateService;
use Illuminate\Console\Command;

class RefreshAddress extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'openShop:refresh-address';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '刷新所有订单的地址';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        OpenShopSignOrderModel::query()
                              ->with(['progressRel', 'siteLocationRel', 'baseInfoRel'])
                              ->get()
                              ->each(function ($item) {
                                  $orderNo = $item->orderNo;

                                  $s = OpenShopAddressModel::autoAdd($orderNo, $item);

                                  $nowStepStatus = $item->progressRel->nowStepStatus ?? '-';

                                  dump("orderNo:{$orderNo} {$nowStepStatus} ".implode(',', $s->toArray()));
                              });
    }

}
